package com.hu.zhcc.shiro.controller.Reponsitory;

import com.github.pagehelper.PageInfo;
import com.hu.zhcc.common.entity.Page;
import com.hu.zhcc.shiro.entity.Reponsitory.REvaluate;
import com.hu.zhcc.shiro.service.Responsitory.EvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/****
 * 评估建议
 */
@RestController
public class EvaluateController {

    @Autowired
    private EvaluateService evaluateService;

    /***
     * 分页及条件查询
     * @param offset
     * @param limit
     * @param ateName
     * @return
     */
    @GetMapping("listEval")
    private Page<REvaluate> evaluateList(String offset, String limit, String ateName) {
        REvaluate evaluate = new REvaluate(ateName);
        Map map = new HashMap();
        map.put("pageIndex", offset);
        map.put("num", limit);
        return evaluateService.selectAll(map, evaluate);
    }

    /***
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("deleteEval{id}")
    private int deleteEval(@PathVariable("id") int id) {
        return evaluateService.deleteByPrimaryKey(id);
    }

    /***
     * 获取当前日期
     * @return
     */
    public String dateFomat() {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(date);
        return format;
    }

    /***
     * 添加
     * @param evalate
     * @return
     */
    @PostMapping("addEval")
    private int addEval(@RequestBody REvaluate evalate) {
        String s = dateFomat();
        evalate.setAteTime(s);
        return evaluateService.insertSelective(evalate);
    }

    /***
     * 修改前查询
     * @param id
     * @return
     */
    @PostMapping("beforeSelect{id}")
    private REvaluate beforeUpdate(@PathVariable("id") int id) {
        return evaluateService.selectBeforeUpdate(id);
    }

    /***
     * 修改
     * @param evalate
     * @return
     */
    @PutMapping("updateEval")
    private int updateEval(@RequestBody REvaluate evalate) {
        return evaluateService.updateByPrimaryKeySelective(evalate);
    }
}
